package com.quanyan.stadium.web.api;

import com.quanyan.api.APIResponse;
import com.quanyan.stadium.api.req.ReqId;
import com.quanyan.stadium.service.commonComponent.DataReductionService;
import com.quanyan.stadium.service.commonComponent.GameMQLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController("exceptionMsgController")
@RequestMapping("/api/stadium/msg")
public class ExceptionMsgController {

    @Autowired
    private DataReductionService dataReductionService;

    @Autowired
    private GameMQLog gameMQLog;

    @RequestMapping(value="/categoryScore", method = RequestMethod.POST)
    public APIResponse<?> categoryScore(@RequestBody ReqId reqId) throws Exception {
        gameMQLog.updateNotifyFinishByMsgId(reqId.getMsgId());
        dataReductionService.gameScheduleCategoryScoreRecord(gameMQLog.getStadiumMsgModelByMsgId(reqId.getMsgId()));
        return APIResponse.returnSuccess();
    }

    @RequestMapping(value="/gradeScore", method = RequestMethod.POST)
    public APIResponse<?> gradeScore(@RequestBody ReqId reqId) throws Exception {
        gameMQLog.updateNotifyFinishByMsgId(reqId.getMsgId());

        dataReductionService.gameScheduleScoreRecord(gameMQLog.getStadiumMsgModelByMsgId(reqId.getMsgId()));
        return APIResponse.returnSuccess();
    }

    @RequestMapping(value="/userGameScheduleInit", method = RequestMethod.POST)
    public APIResponse<?> userGameScheduleInit(@RequestBody ReqId reqId) throws Exception {
        gameMQLog.updateNotifyFinishByMsgId(reqId.getMsgId());
        dataReductionService.userGameScheduleInit(gameMQLog.getStadiumMsgModelByMsgId(reqId.getMsgId()));
        return APIResponse.returnSuccess();
    }

    @RequestMapping(value="/userGameScheduleUpdate", method = RequestMethod.POST)
    public APIResponse<?> userGameScheduleUpdate(@RequestBody ReqId reqId) throws Exception {
        gameMQLog.updateNotifyFinishByMsgId(reqId.getMsgId());
        dataReductionService.userGameScheduleUpdate(gameMQLog.getStadiumMsgModelByMsgId(reqId.getMsgId()));
        return APIResponse.returnSuccess();
    }

    @RequestMapping(value="/userGameScheduleFinish", method = RequestMethod.POST)
    public APIResponse<?> userGameScheduleFinish(@RequestBody ReqId reqId) throws Exception {
        gameMQLog.updateNotifyFinishByMsgId(reqId.getMsgId());
        dataReductionService.userGameScheduleFinally(gameMQLog.getStadiumMsgModelByMsgId(reqId.getMsgId()));
        return APIResponse.returnSuccess();
    }


    @RequestMapping(value="/userGameEventCollect", method = RequestMethod.POST)
    public APIResponse<?> userGameEventCollect(@RequestBody ReqId reqId) throws Exception {
        gameMQLog.updateNotifyFinishByMsgId(reqId.getMsgId());
        dataReductionService.userGameEventCollect(gameMQLog.getStadiumMsgModelByMsgId(reqId.getMsgId()));
        return APIResponse.returnSuccess();
    }


    @RequestMapping(value="/userPKGameEventCollect", method = RequestMethod.POST)
    public APIResponse<?> userPKGameEventCollect(@RequestBody ReqId reqId) throws Exception {
        gameMQLog.updateNotifyFinishByMsgId(reqId.getMsgId());
        dataReductionService.userPKGameEventCollect(gameMQLog.getStadiumMsgModelByMsgId(reqId.getMsgId()));
        return APIResponse.returnSuccess();
    }

    @RequestMapping(value="/userRadarChart", method = RequestMethod.POST)
    public APIResponse<?> userRadarChart(@RequestBody ReqId reqId) throws Exception {
        gameMQLog.updateNotifyFinishByMsgId(reqId.getMsgId());
        dataReductionService.updateGameRadarChartBatch(gameMQLog.getStadiumMsgModelByMsgId(reqId.getMsgId()));
        return APIResponse.returnSuccess();
    }

    @RequestMapping(value="/gameScheduleEnd", method = RequestMethod.POST)
    public APIResponse<?> gameScheduleEnd(@RequestBody ReqId reqId) throws Exception {
        gameMQLog.updateNotifyFinishByMsgId(reqId.getMsgId());
        dataReductionService.generateCurrentRoundPushMsgAndMQ(gameMQLog.getStadiumMsgModelByMsgId(reqId.getMsgId()));
        return APIResponse.returnSuccess();
    }
}
